Can't include Javascript variable in PHP mysql_query call? [on hold]

Posted by user198895 on Server Fault See other posts from Server Fault or by user198895
Published on 2013-11-11T01:16:39Z Indexed on 2013/11/11 3:57 UTC
Read the original article Hit count: 539

Filed under:
|
|
|

I want the PHP mysql_query call to retrieve user values based on the Agency drop-down value but I can't get this to work. Am I unable to include the Javascript variable agency.value in PHP?

                <script type="text/javascript">
                var agency = document.getElementById("agency");
                var user = document.getElementById("user");                 
                agency.onchange = onchange; // change options when agency is changed

                function onchange() {
                    <?php include 'dbConnect.php'; ?>
                    <?php $q = mysql_query("select id as UserID, CONCAT(LastName, ', ' , FirstName) as UserName from users where Agency = " . ?>agency.value<?php . " order by UserName");?>                                               
                    option_html = "<option value=0 selected>- All Users -</option>";
                    <?php while ($row1 = mysql_fetch_array($q)) {?>
                        if (agency.value == 0 || agency.value == '<?php echo $row1[AgencyID]; ?>') {
                            option_html += "<option value=<?php echo $row1[UserID]; ?>><?php echo $row1[UserName]; ?></option>";
                        }
                    <?php } ?>
                    user.innerHTML = option_html;
                }
                </script>   

© Server Fault or respective owner

Related posts about mysql

Related posts about php